﻿package dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.hibernate.Session;

public class DatabaseConnector
{
    private static EntityManager entityManager;
	private static Session session;

	public synchronized static EntityManager getEntityManager() {
		if (entityManager == null)
		{
			EntityManagerFactory factory = Persistence.createEntityManagerFactory("WebSach_SQLServer");
			entityManager = factory.createEntityManager();
		}
		return entityManager;
	}

	public synchronized static Session getHibernateSession() {
		if (session == null)
		{
			session = getEntityManager().unwrap( Session.class );
		}
		return session;
	}

}
